package com.chinapost.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.logging.LogManager;

import org.apache.log4j.Logger;


public class StreamGobbler extends Thread {
	InputStream is;

	String type;
	
	private static final Logger logger = Logger.getLogger(StreamGobbler.class);

	StreamGobbler(InputStream is, String type) {
		this.is = is;
		this.type = type;
	}

	public void run() {
		try {
			InputStreamReader isr = new InputStreamReader(is);
			BufferedReader br = new BufferedReader(isr);
			String line = null;
			while ((line = br.readLine()) != null) {
				if (type.equals("Error"))
					logger.error(line);
				else
					logger.debug(line);
			}
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}
	}
}